namespace ForumsSearch
{
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Windows.Forms;

    public class MainForm : Form
    {
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private System.Collections.Generic.Dictionary<string, string> msdnGroups = new System.Collections.Generic.Dictionary<string, string>();
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private System.Collections.Generic.IDictionary<string, string> msdnForums = new System.Collections.Generic.Dictionary<string, string>();
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private System.Collections.Generic.Dictionary<string, string> techNetGroups = new System.Collections.Generic.Dictionary<string, string>();
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private System.Collections.Generic.Dictionary<string, string> techNetForums = new System.Collections.Generic.Dictionary<string, string>();
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private Label groupLabel;
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private CheckBox commentsOnlyCheckBox;
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private CheckBox questionsOnlyCheckBox;
		private ListBox forumsListBox;
        private TextBox URLTextBox;
        private CheckBox isIDAnswererCheckBox;
        private CheckBox isIDPosterCheckBox;
        private CheckBox isIDAskerCheckBox;
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private ComboBox groupsComboBox;

		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private void InitializeDictionaries()
		{
			msdnGroups.Add("", "<All Groups>");
//			groups.Add("1", "Administrators / Moderators");
			msdnGroups.Add("14", "Site Feedback for forums.microsoft.com/msdn");
			msdnGroups.Add("12", ".NET Development");
			msdnGroups.Add("35", "Visual Studio Express Editions");
			msdnGroups.Add("11", "Smart Device Development");
			msdnGroups.Add("10", "Visual Basic");
			msdnGroups.Add("9", "Visual C#");
			msdnGroups.Add("8", "Visual C++");
			msdnGroups.Add("7", "Visual J#");
			msdnGroups.Add("17", "Visual FoxPro");
			msdnGroups.Add("6", "Visual Studio");
			msdnGroups.Add("5", "Visual Studio Team System");
			msdnGroups.Add("4", "Visual Studio Tools for Office");
			msdnGroups.Add("2", "Windows Forms");
			msdnGroups.Add("153", "Visual Studio Orcas (Pre-Release)");
			msdnGroups.Add("20", "Game Technologies:  DirectX, XNA, XACT, etc.");
			msdnGroups.Add("26", "System Center Capacity Planner");
			msdnGroups.Add("19", "SQL Server");
			msdnGroups.Add("109", "Audio and Video Development");
			msdnGroups.Add("58", "Architecture");
			msdnGroups.Add("23", "Windows Live Developer Forums");
			msdnGroups.Add("24", "Software Development for Windows Vista");
			msdnGroups.Add("234", "Windows Networking Development");
			msdnGroups.Add("25", "Windows Search Clients");
			msdnGroups.Add("18", "Microsoft ISV Community Center Forums");

			msdnForums.Add("", "<All Forums>");
//			forums.Add("1", "Administrators");
//			forums.Add("2", "Moderators");
//			forums.Add("3", "Reporting Forums");
			msdnForums.Add("54", "Announcements");
			msdnForums.Add("52", "Suggestions for Forums website");
			msdnForums.Add("53", "Bug Reports for Forums website");
			msdnForums.Add("45", ".NET Framework Data Access and Storage");
			msdnForums.Add("38", "XML and the .NET Framework");
			msdnForums.Add("40", ".NET Framework Networking and Communication ");
			msdnForums.Add("41", ".NET Remoting and Runtime Serialization");
			msdnForums.Add("46", "ASP.NET Web Services and XML Serialization");
			msdnForums.Add("39", ".NET Base Class Library");
			msdnForums.Add("44", "Common Language Runtime");
			msdnForums.Add("47", "JScript for the .NET Framework");
			msdnForums.Add("42", "64-Bit .NET Framework Development.");
			msdnForums.Add("98", "FxCop Managed Code Analysis");
			msdnForums.Add("123", "LINQ Project General");
			msdnForums.Add("159", "Visual Basic Express Edition");
			msdnForums.Add("160", "Visual C# Express Edition");
			msdnForums.Add("161", "Visual C++ Express Edition");
			msdnForums.Add("24", "Installing and Registering Visual Studio Express Editions");
			msdnForums.Add("76", "Device Emulator General");
			msdnForums.Add("33", ".NET Compact Framework");
			msdnForums.Add("34", "Smart Devices General");
			msdnForums.Add("36", "Smart Devices VB and C# Projects");
			msdnForums.Add("35", "Smart Devices Native C++ Development");
			msdnForums.Add("65", "Visual Basic IDE");
			msdnForums.Add("64", "Visual Basic Language");
			msdnForums.Add("32", "Visual Basic General");
			msdnForums.Add("31", "Visual C# General");
			msdnForums.Add("59", "Visual C# Language");
			msdnForums.Add("58", "Visual C# IDE");
			msdnForums.Add("29", "Visual C++ General");
			msdnForums.Add("96", "Visual C++ Language");
			msdnForums.Add("28", "Visual J# General");
			msdnForums.Add("60", "Visual FoxPro General");
			msdnForums.Add("26", "Visual Studio Setup and Installation");
			msdnForums.Add("57", "Visual Studio Extensibility");
			msdnForums.Add("56", "Visual Studio Debugger");
			msdnForums.Add("27", "Visual Studio MSBuild");
			msdnForums.Add("25", "Visual Studio General");
			msdnForums.Add("291", "Developer Aftermarket Solutions and Powertoys");
			msdnForums.Add("50", "Visual Studio Source Control and SourceSafe");
			msdnForums.Add("55", "Visual Studio Class Designer");
			msdnForums.Add("78", "Visual Studio Guidance Automation Toolkit ");
			msdnForums.Add("75", "Visual Studio Report Controls");
			msdnForums.Add("77", "Crystal Reports for Visual Studio");
			msdnForums.Add("66", "Developer Documentation and Help System");
			msdnForums.Add("20", "Visual Studio Team System - General");
			msdnForums.Add("21", "Visual Studio Team System - Architects");
			msdnForums.Add("18", "Visual Studio Team System - Developers");
			msdnForums.Add("19", "Visual Studio Team System - Testers");
			msdnForums.Add("725", "Visual Studio Team System - Database Professionals");
			msdnForums.Add("63", "Visual Studio Team System - Microsoft Solutions Framework (MSF)");
			msdnForums.Add("61", "Visual Studio Team System - Domain-Specific Language Tools");
			msdnForums.Add("22", "Team Foundation Server - General");
			msdnForums.Add("68", "Team Foundation Server - Setup");
			msdnForums.Add("477", "Team Foundation Server - Administration");
			msdnForums.Add("481", "Team Foundation Server - Build Automation");
			msdnForums.Add("482", "Team Foundation Server - Process Templates");
			msdnForums.Add("480", "Team Foundation Server - Reporting");
			msdnForums.Add("478", "Team Foundation Server - Version Control");
			msdnForums.Add("479", "Team Foundation Server - Work Item Tracking");
			msdnForums.Add("16", "Visual Studio Tools for Office");
			msdnForums.Add("8", "Windows Forms General");
			msdnForums.Add("5", "Windows Forms Designer");
			msdnForums.Add("6", "ClickOnce and Setup & Deployment Projects");
			msdnForums.Add("7", "Windows Forms Data Controls and Databinding");
			msdnForums.Add("67", "Windows Forms Sample Applications");
			msdnForums.Add("533", "ADO.NET Technology Preview");
			msdnForums.Add("99", "Game Technologies: General");
			msdnForums.Add("106", "Game Technologies: DirectX 101");
			msdnForums.Add("100", "Game Technologies: Graphics");
			msdnForums.Add("323", "Game Technologies: XACT");
			msdnForums.Add("386", "Game Technolgies: XNA Build");
			msdnForums.Add("785", "Direct3D 10");
			msdnForums.Add("128", "Capacity Planner General ");
			msdnForums.Add("80", "SQL Server Integration Services");
			msdnForums.Add("81", "Data Mining");
			msdnForums.Add("82", "SQL Server Reporting Services");
			msdnForums.Add("83", "SQL Server Analysis Services");
			msdnForums.Add("84", "SQL Server Tools General");
			msdnForums.Add("85", "Transact-SQL");
			msdnForums.Add("86", ".NET Framework inside SQL Server");
			msdnForums.Add("87", "SQL Server Data Access");
			msdnForums.Add("88", "SQL Server SMO/DMO");
			msdnForums.Add("89", "SQL Server XML");
			msdnForums.Add("90", "SQL Server Replication");
			msdnForums.Add("91", "SQL Service Broker");
			msdnForums.Add("92", "SQL Server Security");
			msdnForums.Add("93", "SQL Server Database Engine");
			msdnForums.Add("94", "SQL Server Documentation");
			msdnForums.Add("95", "SQL Server Setup & Upgrade");
			msdnForums.Add("744", "SQL Server Disaster Recovery and Availability");
			msdnForums.Add("97", "SQL Server Notification Services");
			msdnForums.Add("152", "SQL Server Mobile");
			msdnForums.Add("158", "Getting started with SQL Server");
			msdnForums.Add("227", "Database Mirroring");
			msdnForums.Add("385", "SQL Express");
			msdnForums.Add("387", "Media Foundation Development");
			msdnForums.Add("527", "HD DVD Interactivity Authoring");
			msdnForums.Add("228", "Architecture General");
			msdnForums.Add("229", "Modeling and Tools");
			msdnForums.Add("350", "Architecture Events");
			msdnForums.Add("536", "Windows Live General: Development");
			msdnForums.Add("111", "Windows Live Search: Development");
			msdnForums.Add("112", "Windows Live Messenger: Development");
			msdnForums.Add("198", "MSN Spaces: Development");
			msdnForums.Add("534", "Windows Live Chatter: Development");
			msdnForums.Add("537", "Virtual Earth: Map Control Development");
			msdnForums.Add("646", "Windows Live ID: Development ");
			msdnForums.Add("113", "Search, Organize and Visualize in Windows Vista");
			msdnForums.Add("129", "DirectShow Development");
			msdnForums.Add("114", "Mobile PC and Tablet PC Development");
			msdnForums.Add("116", "Security for Applications in Windows Vista");
			msdnForums.Add("117", "UI Development for Windows Vista");
			msdnForums.Add("118", "Windows Communication Foundation (\"Indigo\")");
			msdnForums.Add("119", "Windows Presentation Foundation (\"Avalon\")");
			msdnForums.Add("120", "General Windows Vista Development Issues");
			msdnForums.Add("121", "Windows SDK forum");
			msdnForums.Add("122", "Windows Workflow Foundation");
			msdnForums.Add("126", "XML Paper Specification (XPS)");
			msdnForums.Add("169", "WPF Designer (\"Cider\")");
			msdnForums.Add("351", "Vista Pro-Audio Application Development");
			msdnForums.Add("352", "Microsoft UI Automation");
			msdnForums.Add("388", "Transactions Programming");
			msdnForums.Add("490", "Optical Platform Discussion");
			msdnForums.Add("784", "Windows CardSpace (\"InfoCard\")");
			msdnForums.Add("825", "Network Quality of Service (QoS/qWAVE)");
			msdnForums.Add("127", "Windows Desktop Search Development");
			msdnForums.Add("847", "Windows Desktop Search Help");
			msdnForums.Add("848", "Windows Live Search Center Development");
			msdnForums.Add("849", "Windows Live Search Center Help");
			msdnForums.Add("69", "ISV Open Discussions");
			msdnForums.Add("71", "Partnering with Microsoft");
			msdnForums.Add("231", "Architecture, Tools, and Process for ISVs");
			msdnForums.Add("74", "Visual Basic for Applications (VBA) ");

			techNetGroups.Add("", "<All Groups>");
			techNetForums.Add("", "<All Forums>");
		}


		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">
		/// Added calls to InitializeDictionaries and UpdateContols
		/// </revision>
		/// </revisionHistory>
		public MainForm()
        {
			this.InitializeDictionaries();
			this.InitializeComponent();
			base.AutoScaleMode = AutoScaleMode.Font;

			this.UpdateControls();
		}
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">
		/// changed assignment of forumID to selected value of forumsComboBox.
		/// added assignment to SearchTerms.isComment field
		/// added Debug.Assert
		/// </revision>
		/// <revision author="Peter Ritchie" date="14-jul=06">
		/// Added support for forums listbox and SearchTerms.ForumIDs
		/// </revision>
        /// <revision author="Moayad Mardini [mardini]" date="14-August-2006">
        /// Change [isIDAnswerer, isIDAsker and isIDContributor]' values
        /// </revision>
        /// <revision author="Moayad Mardini [mardini]" date="17-August-2006">
        /// Validate user inputs when search with [Asker/Poster/Answerer]'s ID instead of name
        /// </revision>
		/// </revisionHistory>
		private void copyInputs()
        {
			Debug.Assert(!(commentsOnlyCheckBox.Checked && questionsOnlyCheckBox.Checked));
            this.searchControl = new Search();
            this.searchControl.Terms.UserNameAnswerer = this.userNameOrIDTextBox.Text;
            this.searchControl.Terms.FreeText = this.keywordsTextBox.Text;
            this.searchControl.Terms.UserNameAsker = this.askerNameOrIDTextBox.Text;
            this.searchControl.Terms.UserNameContributor = this.posterNameOrIDTextBox.Text;
            this.searchControl.Terms.SiteID = this.siteComboBox.Text;
            this.searchControl.Terms.isIDAnswerer = this.isIDAnswererCheckBox.Checked;
            if (this.searchControl.Terms.isIDAnswerer == true)
            {
                if (IsInteger(this.searchControl.Terms.UserNameAnswerer) == false && !String.IsNullOrEmpty(this.searchControl.Terms.UserNameAnswerer))
                {
                    if (MessageBox.Show(this, ForumsSearch.Properties.Resources.InvaildAnswererIDMessage , @"Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        this.searchControl.Terms.isIDAnswerer = false;
                    }
                }
            }
            this.searchControl.Terms.isIDAsker = this.isIDAskerCheckBox.Checked;
            if (this.searchControl.Terms.isIDAsker  == true)
            {
                if (IsInteger(this.searchControl.Terms.UserNameAsker) == false && !String.IsNullOrEmpty(this.searchControl.Terms.UserNameAsker ))
                {
                    if (MessageBox.Show(this, ForumsSearch.Properties.Resources.InvaildAskerIDMessage , @"Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        this.searchControl.Terms.isIDAsker = false;
                    }
                }
            }
            this.searchControl.Terms.isIDContributor = this.isIDPosterCheckBox.Checked;
            if (this.searchControl.Terms.isIDContributor  == true)
            {
                if (IsInteger(this.searchControl.Terms.UserNameContributor) == false && !String.IsNullOrEmpty(this.searchControl.Terms.UserNameContributor ))
                {
                    if (MessageBox.Show(this,ForumsSearch.Properties.Resources.InvaildPosterIDMessage  , @"Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        this.searchControl.Terms.isIDContributor  = false;
                    }
                }
            }
            if (this.helpfulCheckBox.Checked)
            {
                this.searchControl.Terms.Helpful = true;
            }
            if (this.onlyAnsweredRadioButton.Checked)
            {
                this.searchControl.Terms.IsAnswered = 1;
            }
            else if (this.onlyUnansweredRadioButton.Checked)
            {
                this.searchControl.Terms.IsAnswered = 0;
            }
            else
            {
                this.searchControl.Terms.IsAnswered = 2;
            }
			this.searchControl.Terms.GroupID = groupsComboBox.SelectedValue;
			this.searchControl.Terms.IsQuestion = questionsOnlyCheckBox.Checked;
			this.searchControl.Terms.IsComment = commentsOnlyCheckBox.Checked;
			this.searchControl.Terms.ForumIDs.Clear();
			if (this.forumsListBox.SelectedIndices.Count > 0)
			{
				foreach (System.Collections.Generic.KeyValuePair<string, string> pair in this.forumsListBox.SelectedItems)
				{
					String text = pair.Key as String;
					if (!String.IsNullOrEmpty(text))
					{
						this.searchControl.Terms.ForumIDs.Add(text);
					}
				}
			}
		}
        /// <revisionHistory>
        /// <revision author="Moayad Mardini [mardini]" date="17-August-2006">
        /// Create this function to validate user inputs when search with [Asker/Poster/Answerer]'s ID instead of name
        /// </revision>
        /// </revisionHistory>
        private static bool IsInteger(string Value)
        {
            try
            {
                Convert.ToInt32(Value);
                return true;
            }
            catch
            {
                return false;
            }
        }

        private void copyRSS_Click(object sender, EventArgs e)
        {
            /// <revisionHistory>
            /// <revision author="Moayad Mardini [mardini]" date="14-August-2006">
            /// Show the generated URL in a read-only text-box, not only copy it to the clipboard
            /// </revision>
            /// </revisionHistory>
            this.copyInputs();
            this.URLTextBox.Text = this.searchControl.GetRSSURL();
            Clipboard.SetText(this.URLTextBox.Text);
        }

        private void copyToClipboardButton_Click(object sender, EventArgs e)
        {
            /// <revisionHistory>
            /// <revision author="Moayad Mardini [mardini]" date="14-August-2006">
            /// Show the generated URL in a read-only text-box, not only copy it to the clipboard
            /// </revision>
            /// </revisionHistory>
            this.copyInputs();
            this.URLTextBox.Text = this.searchControl.GetURL();
            Clipboard.SetText(this.URLTextBox.Text);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.searchOptionsGroupBox = new System.Windows.Forms.GroupBox();
            this.isIDAnswererCheckBox = new System.Windows.Forms.CheckBox();
            this.isIDPosterCheckBox = new System.Windows.Forms.CheckBox();
            this.isIDAskerCheckBox = new System.Windows.Forms.CheckBox();
            this.answerFiltersGroupBox = new System.Windows.Forms.GroupBox();
            this.allQuestionsRadioButton = new System.Windows.Forms.RadioButton();
            this.onlyUnansweredRadioButton = new System.Windows.Forms.RadioButton();
            this.onlyAnsweredRadioButton = new System.Windows.Forms.RadioButton();
            this.forumsListBox = new System.Windows.Forms.ListBox();
            this.commentsOnlyCheckBox = new System.Windows.Forms.CheckBox();
            this.questionsOnlyCheckBox = new System.Windows.Forms.CheckBox();
            this.groupsComboBox = new System.Windows.Forms.ComboBox();
            this.helpfulCheckBox = new System.Windows.Forms.CheckBox();
            this.posterNameOrIDLabel = new System.Windows.Forms.Label();
            this.posterNameOrIDTextBox = new System.Windows.Forms.TextBox();
            this.siteComboBox = new System.Windows.Forms.ComboBox();
            this.siteLabel = new System.Windows.Forms.Label();
            this.groupLabel = new System.Windows.Forms.Label();
            this.forumLabel = new System.Windows.Forms.Label();
            this.askerNameLabel = new System.Windows.Forms.Label();
            this.askerNameOrIDTextBox = new System.Windows.Forms.TextBox();
            this.keywordsTextBox = new System.Windows.Forms.TextBox();
            this.keywordsLabel = new System.Windows.Forms.Label();
            this.userNameOrIDTextBox = new System.Windows.Forms.TextBox();
            this.answererNameOrIDLabel = new System.Windows.Forms.Label();
            this.searchButton = new System.Windows.Forms.Button();
            this.copyToClipboardButton = new System.Windows.Forms.Button();
            this.copyRSS = new System.Windows.Forms.Button();
            this.URLTextBox = new System.Windows.Forms.TextBox();
            this.searchOptionsGroupBox.SuspendLayout();
            this.answerFiltersGroupBox.SuspendLayout();
            this.SuspendLayout();
            // 
            // searchOptionsGroupBox
            // 
            this.searchOptionsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.searchOptionsGroupBox.Controls.Add(this.isIDAnswererCheckBox);
            this.searchOptionsGroupBox.Controls.Add(this.isIDPosterCheckBox);
            this.searchOptionsGroupBox.Controls.Add(this.isIDAskerCheckBox);
            this.searchOptionsGroupBox.Controls.Add(this.answerFiltersGroupBox);
            this.searchOptionsGroupBox.Controls.Add(this.forumsListBox);
            this.searchOptionsGroupBox.Controls.Add(this.commentsOnlyCheckBox);
            this.searchOptionsGroupBox.Controls.Add(this.questionsOnlyCheckBox);
            this.searchOptionsGroupBox.Controls.Add(this.groupsComboBox);
            this.searchOptionsGroupBox.Controls.Add(this.helpfulCheckBox);
            this.searchOptionsGroupBox.Controls.Add(this.posterNameOrIDLabel);
            this.searchOptionsGroupBox.Controls.Add(this.posterNameOrIDTextBox);
            this.searchOptionsGroupBox.Controls.Add(this.siteComboBox);
            this.searchOptionsGroupBox.Controls.Add(this.siteLabel);
            this.searchOptionsGroupBox.Controls.Add(this.groupLabel);
            this.searchOptionsGroupBox.Controls.Add(this.forumLabel);
            this.searchOptionsGroupBox.Controls.Add(this.askerNameLabel);
            this.searchOptionsGroupBox.Controls.Add(this.askerNameOrIDTextBox);
            this.searchOptionsGroupBox.Controls.Add(this.keywordsTextBox);
            this.searchOptionsGroupBox.Controls.Add(this.keywordsLabel);
            this.searchOptionsGroupBox.Controls.Add(this.userNameOrIDTextBox);
            this.searchOptionsGroupBox.Controls.Add(this.answererNameOrIDLabel);
            this.searchOptionsGroupBox.Location = new System.Drawing.Point(12, 12);
            this.searchOptionsGroupBox.Name = "searchOptionsGroupBox";
            this.searchOptionsGroupBox.Size = new System.Drawing.Size(566, 300);
            this.searchOptionsGroupBox.TabIndex = 0;
            this.searchOptionsGroupBox.TabStop = false;
            this.searchOptionsGroupBox.Text = "Search Options";
            // 
            // isIDAnswererCheckBox
            // 
            this.isIDAnswererCheckBox.AutoSize = true;
            this.isIDAnswererCheckBox.Location = new System.Drawing.Point(128, 58);
            this.isIDAnswererCheckBox.Name = "isIDAnswererCheckBox";
            this.isIDAnswererCheckBox.Size = new System.Drawing.Size(49, 17);
            this.isIDAnswererCheckBox.TabIndex = 22;
            this.isIDAnswererCheckBox.Text = "Is ID";
            this.isIDAnswererCheckBox.UseVisualStyleBackColor = true;
            // 
            // isIDPosterCheckBox
            // 
            this.isIDPosterCheckBox.AutoSize = true;
            this.isIDPosterCheckBox.Location = new System.Drawing.Point(119, 97);
            this.isIDPosterCheckBox.Name = "isIDPosterCheckBox";
            this.isIDPosterCheckBox.Size = new System.Drawing.Size(49, 17);
            this.isIDPosterCheckBox.TabIndex = 16;
            this.isIDPosterCheckBox.Text = "Is ID";
            this.isIDPosterCheckBox.UseVisualStyleBackColor = true;
            // 
            // isIDAskerCheckBox
            // 
            this.isIDAskerCheckBox.AutoSize = true;
            this.isIDAskerCheckBox.Location = new System.Drawing.Point(257, 58);
            this.isIDAskerCheckBox.Name = "isIDAskerCheckBox";
            this.isIDAskerCheckBox.Size = new System.Drawing.Size(49, 17);
            this.isIDAskerCheckBox.TabIndex = 15;
            this.isIDAskerCheckBox.Text = "Is ID";
            this.isIDAskerCheckBox.UseVisualStyleBackColor = true;
            // 
            // answerFiltersGroupBox
            // 
            this.answerFiltersGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.answerFiltersGroupBox.Controls.Add(this.allQuestionsRadioButton);
            this.answerFiltersGroupBox.Controls.Add(this.onlyUnansweredRadioButton);
            this.answerFiltersGroupBox.Controls.Add(this.onlyAnsweredRadioButton);
            this.answerFiltersGroupBox.Location = new System.Drawing.Point(384, 103);
            this.answerFiltersGroupBox.Name = "answerFiltersGroupBox";
            this.answerFiltersGroupBox.Size = new System.Drawing.Size(176, 94);
            this.answerFiltersGroupBox.TabIndex = 18;
            this.answerFiltersGroupBox.TabStop = false;
            this.answerFiltersGroupBox.Text = "Answer Filters";
            // 
            // allQuestionsRadioButton
            // 
            this.allQuestionsRadioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.allQuestionsRadioButton.AutoSize = true;
            this.allQuestionsRadioButton.Location = new System.Drawing.Point(13, 68);
            this.allQuestionsRadioButton.Name = "allQuestionsRadioButton";
            this.allQuestionsRadioButton.Size = new System.Drawing.Size(87, 17);
            this.allQuestionsRadioButton.TabIndex = 9;
            this.allQuestionsRadioButton.TabStop = true;
            this.allQuestionsRadioButton.Text = "All Questions";
            this.allQuestionsRadioButton.UseVisualStyleBackColor = true;
            // 
            // onlyUnansweredRadioButton
            // 
            this.onlyUnansweredRadioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.onlyUnansweredRadioButton.AutoSize = true;
            this.onlyUnansweredRadioButton.Location = new System.Drawing.Point(13, 45);
            this.onlyUnansweredRadioButton.Name = "onlyUnansweredRadioButton";
            this.onlyUnansweredRadioButton.Size = new System.Drawing.Size(110, 17);
            this.onlyUnansweredRadioButton.TabIndex = 8;
            this.onlyUnansweredRadioButton.TabStop = true;
            this.onlyUnansweredRadioButton.Text = "Only Unanswered";
            this.onlyUnansweredRadioButton.UseVisualStyleBackColor = true;
            // 
            // onlyAnsweredRadioButton
            // 
            this.onlyAnsweredRadioButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.onlyAnsweredRadioButton.AutoSize = true;
            this.onlyAnsweredRadioButton.Location = new System.Drawing.Point(12, 22);
            this.onlyAnsweredRadioButton.Name = "onlyAnsweredRadioButton";
            this.onlyAnsweredRadioButton.Size = new System.Drawing.Size(98, 17);
            this.onlyAnsweredRadioButton.TabIndex = 7;
            this.onlyAnsweredRadioButton.TabStop = true;
            this.onlyAnsweredRadioButton.Text = "Only Answered";
            this.onlyAnsweredRadioButton.UseVisualStyleBackColor = true;
            // 
            // forumsListBox
            // 
            this.forumsListBox.FormattingEnabled = true;
            this.forumsListBox.Location = new System.Drawing.Point(9, 153);
            this.forumsListBox.Name = "forumsListBox";
            this.forumsListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
            this.forumsListBox.Size = new System.Drawing.Size(359, 95);
            this.forumsListBox.TabIndex = 21;
            this.forumsListBox.SelectedIndexChanged += new System.EventHandler(this.forumsListBox_SelectedIndexChanged);
            // 
            // commentsOnlyCheckBox
            // 
            this.commentsOnlyCheckBox.AutoSize = true;
            this.commentsOnlyCheckBox.Location = new System.Drawing.Point(395, 35);
            this.commentsOnlyCheckBox.Name = "commentsOnlyCheckBox";
            this.commentsOnlyCheckBox.Size = new System.Drawing.Size(101, 17);
            this.commentsOnlyCheckBox.TabIndex = 20;
            this.commentsOnlyCheckBox.Text = "Comments Only";
            this.commentsOnlyCheckBox.UseVisualStyleBackColor = true;
            this.commentsOnlyCheckBox.CheckedChanged += new System.EventHandler(this.commentsOnlyCheckBox_CheckedChanged);
            // 
            // questionsOnlyCheckBox
            // 
            this.questionsOnlyCheckBox.AutoSize = true;
            this.questionsOnlyCheckBox.Location = new System.Drawing.Point(395, 58);
            this.questionsOnlyCheckBox.Name = "questionsOnlyCheckBox";
            this.questionsOnlyCheckBox.Size = new System.Drawing.Size(99, 17);
            this.questionsOnlyCheckBox.TabIndex = 20;
            this.questionsOnlyCheckBox.Text = "Questions Only";
            this.questionsOnlyCheckBox.UseVisualStyleBackColor = true;
            this.questionsOnlyCheckBox.CheckedChanged += new System.EventHandler(this.questionsOnlyCheckBox_CheckedChanged);
            // 
            // groupsComboBox
            // 
            this.groupsComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.groupsComboBox.FormattingEnabled = true;
            this.groupsComboBox.Location = new System.Drawing.Point(9, 267);
            this.groupsComboBox.Name = "groupsComboBox";
            this.groupsComboBox.Size = new System.Drawing.Size(359, 21);
            this.groupsComboBox.TabIndex = 19;
            // 
            // helpfulCheckBox
            // 
            this.helpfulCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.helpfulCheckBox.AutoSize = true;
            this.helpfulCheckBox.Location = new System.Drawing.Point(394, 80);
            this.helpfulCheckBox.Name = "helpfulCheckBox";
            this.helpfulCheckBox.Size = new System.Drawing.Size(126, 17);
            this.helpfulCheckBox.TabIndex = 10;
            this.helpfulCheckBox.Text = "Helpful Threads Only";
            this.helpfulCheckBox.UseVisualStyleBackColor = true;
            // 
            // posterNameOrIDLabel
            // 
            this.posterNameOrIDLabel.AutoSize = true;
            this.posterNameOrIDLabel.Location = new System.Drawing.Point(6, 98);
            this.posterNameOrIDLabel.Name = "posterNameOrIDLabel";
            this.posterNameOrIDLabel.Size = new System.Drawing.Size(107, 13);
            this.posterNameOrIDLabel.TabIndex = 16;
            this.posterNameOrIDLabel.Text = "Poster Name (or ID):";
            // 
            // posterNameOrIDTextBox
            // 
            this.posterNameOrIDTextBox.Location = new System.Drawing.Point(9, 114);
            this.posterNameOrIDTextBox.Name = "posterNameOrIDTextBox";
            this.posterNameOrIDTextBox.Size = new System.Drawing.Size(153, 20);
            this.posterNameOrIDTextBox.TabIndex = 4;
            // 
            // siteComboBox
            // 
            this.siteComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.siteComboBox.FormattingEnabled = true;
            this.siteComboBox.Items.AddRange(new object[] {
            "MSDN",
            "TechNet"});
            this.siteComboBox.Location = new System.Drawing.Point(186, 113);
            this.siteComboBox.Name = "siteComboBox";
            this.siteComboBox.Size = new System.Drawing.Size(182, 21);
            this.siteComboBox.TabIndex = 6;
            this.siteComboBox.SelectedIndexChanged += new System.EventHandler(this.siteComboBox_SelectedIndexChanged);
            // 
            // siteLabel
            // 
            this.siteLabel.AutoSize = true;
            this.siteLabel.Location = new System.Drawing.Point(183, 97);
            this.siteLabel.Name = "siteLabel";
            this.siteLabel.Size = new System.Drawing.Size(29, 13);
            this.siteLabel.TabIndex = 10;
            this.siteLabel.Text = "Site:";
            // 
            // groupLabel
            // 
            this.groupLabel.AutoSize = true;
            this.groupLabel.Location = new System.Drawing.Point(6, 251);
            this.groupLabel.Name = "groupLabel";
            this.groupLabel.Size = new System.Drawing.Size(40, 13);
            this.groupLabel.TabIndex = 8;
            this.groupLabel.Text = "Group:";
            // 
            // forumLabel
            // 
            this.forumLabel.AutoSize = true;
            this.forumLabel.Location = new System.Drawing.Point(6, 137);
            this.forumLabel.Name = "forumLabel";
            this.forumLabel.Size = new System.Drawing.Size(219, 13);
            this.forumLabel.TabIndex = 8;
            this.forumLabel.Text = "Forum: (CTRL-click to select multiple forums)";
            // 
            // askerNameLabel
            // 
            this.askerNameLabel.AutoSize = true;
            this.askerNameLabel.Location = new System.Drawing.Point(183, 58);
            this.askerNameLabel.Name = "askerNameLabel";
            this.askerNameLabel.Size = new System.Drawing.Size(68, 13);
            this.askerNameLabel.TabIndex = 7;
            this.askerNameLabel.Text = "Asker Name:";
            // 
            // askerNameOrIDTextBox
            // 
            this.askerNameOrIDTextBox.Location = new System.Drawing.Point(186, 75);
            this.askerNameOrIDTextBox.Name = "askerNameOrIDTextBox";
            this.askerNameOrIDTextBox.Size = new System.Drawing.Size(182, 20);
            this.askerNameOrIDTextBox.TabIndex = 3;
            // 
            // keywordsTextBox
            // 
            this.keywordsTextBox.Location = new System.Drawing.Point(9, 35);
            this.keywordsTextBox.Name = "keywordsTextBox";
            this.keywordsTextBox.Size = new System.Drawing.Size(359, 20);
            this.keywordsTextBox.TabIndex = 1;
            // 
            // keywordsLabel
            // 
            this.keywordsLabel.AutoSize = true;
            this.keywordsLabel.Location = new System.Drawing.Point(6, 19);
            this.keywordsLabel.Name = "keywordsLabel";
            this.keywordsLabel.Size = new System.Drawing.Size(58, 13);
            this.keywordsLabel.TabIndex = 3;
            this.keywordsLabel.Text = "Keywords:";
            // 
            // userNameOrIDTextBox
            // 
            this.userNameOrIDTextBox.Location = new System.Drawing.Point(9, 75);
            this.userNameOrIDTextBox.Name = "userNameOrIDTextBox";
            this.userNameOrIDTextBox.Size = new System.Drawing.Size(153, 20);
            this.userNameOrIDTextBox.TabIndex = 2;
            // 
            // answererNameOrIDLabel
            // 
            this.answererNameOrIDLabel.AutoSize = true;
            this.answererNameOrIDLabel.Location = new System.Drawing.Point(6, 59);
            this.answererNameOrIDLabel.Name = "answererNameOrIDLabel";
            this.answererNameOrIDLabel.Size = new System.Drawing.Size(122, 13);
            this.answererNameOrIDLabel.TabIndex = 0;
            this.answererNameOrIDLabel.Text = "Answerer Name (or ID):";
            // 
            // searchButton
            // 
            this.searchButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.searchButton.Location = new System.Drawing.Point(499, 319);
            this.searchButton.Name = "searchButton";
            this.searchButton.Size = new System.Drawing.Size(79, 23);
            this.searchButton.TabIndex = 11;
            this.searchButton.Text = "MSN Search";
            this.searchButton.UseVisualStyleBackColor = true;
            this.searchButton.Click += new System.EventHandler(this.searchButton_Click);
            // 
            // copyToClipboardButton
            // 
            this.copyToClipboardButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.copyToClipboardButton.Location = new System.Drawing.Point(416, 319);
            this.copyToClipboardButton.Name = "copyToClipboardButton";
            this.copyToClipboardButton.Size = new System.Drawing.Size(77, 23);
            this.copyToClipboardButton.TabIndex = 12;
            this.copyToClipboardButton.Text = "Copy URL";
            this.copyToClipboardButton.UseVisualStyleBackColor = true;
            this.copyToClipboardButton.Click += new System.EventHandler(this.copyToClipboardButton_Click);
            // 
            // copyRSS
            // 
            this.copyRSS.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.copyRSS.Location = new System.Drawing.Point(335, 319);
            this.copyRSS.Name = "copyRSS";
            this.copyRSS.Size = new System.Drawing.Size(75, 23);
            this.copyRSS.TabIndex = 13;
            this.copyRSS.Text = "Copy RSS";
            this.copyRSS.UseVisualStyleBackColor = true;
            this.copyRSS.Click += new System.EventHandler(this.copyRSS_Click);
            // 
            // URLTextBox
            // 
            this.URLTextBox.Location = new System.Drawing.Point(12, 321);
            this.URLTextBox.Name = "URLTextBox";
            this.URLTextBox.ReadOnly = true;
            this.URLTextBox.Size = new System.Drawing.Size(317, 20);
            this.URLTextBox.TabIndex = 14;
            // 
            // MainForm
            // 
            this.ClientSize = new System.Drawing.Size(590, 351);
            this.Controls.Add(this.URLTextBox);
            this.Controls.Add(this.copyRSS);
            this.Controls.Add(this.copyToClipboardButton);
            this.Controls.Add(this.searchButton);
            this.Controls.Add(this.searchOptionsGroupBox);
            this.Name = "MainForm";
            this.Text = "Microsoft Forums MSN Search Constructor";
            this.Load += new System.EventHandler(this.MainForm_Load);
            this.searchOptionsGroupBox.ResumeLayout(false);
            this.searchOptionsGroupBox.PerformLayout();
            this.answerFiltersGroupBox.ResumeLayout(false);
            this.answerFiltersGroupBox.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">
		/// Added initialization of siteComboBox.SelectedIndex
		/// </revision>
		/// </revisionHistory>
		private void MainForm_Load(object sender, EventArgs e)
        {
			siteComboBox.SelectedIndex = 0;
        }

        private void searchButton_Click(object sender, EventArgs e)
        {
            /// <revisionHistory>
            /// <revision author="Moayad Mardini [mardini]" date="14-August-2006">
            /// Show the generated URL in a read-only text-box, not only open it in the internet-browser
            /// </revision>
            /// </revisionHistory>
            this.copyInputs();
            this.URLTextBox.Text = this.searchControl.GetURL();
            Process.Start(this.URLTextBox.Text);
        }


        private RadioButton allQuestionsRadioButton;
        private Label askerNameLabel;
        private TextBox askerNameOrIDTextBox;
        private IContainer components;
        private Button copyRSS;
		private Button copyToClipboardButton;
        private GroupBox searchOptionsGroupBox;
        private GroupBox answerFiltersGroupBox;
        private CheckBox helpfulCheckBox;
        private TextBox keywordsTextBox;
        private Label answererNameOrIDLabel;
        private Label keywordsLabel;
        private Label forumLabel;
        private Label siteLabel;
        private Label posterNameOrIDLabel;
        private RadioButton onlyAnsweredRadioButton;
        private RadioButton onlyUnansweredRadioButton;
        private TextBox posterNameOrIDTextBox;
        private Button searchButton;
        private Search searchControl;
        private ComboBox siteComboBox;
        private TextBox userNameOrIDTextBox;

		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">
		/// </revision>
		private void siteComboBox_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.groupsComboBox.DataSource = null;
			if (siteComboBox.SelectedItem as String == "MSDN")
			{
				BindingSource bs = new BindingSource();
				bs.DataSource = msdnGroups;
				this.groupsComboBox.DataSource = bs;
				bs = new BindingSource();
				bs.DataSource = msdnForums;
				forumsListBox.DataSource = bs;
			}
			else if (siteComboBox.SelectedItem as String == "TechNet")
			{
				BindingSource bs = new BindingSource();
				bs.DataSource = techNetGroups;
				this.groupsComboBox.DataSource = bs;
				forumsListBox.DataSource = bs;
				bs = new BindingSource();
				bs.DataSource = techNetForums;
				forumsListBox.DataSource = bs;
			}
			if (this.groupsComboBox.DataSource != null)
			{
				this.groupsComboBox.DisplayMember = "Value";
				this.groupsComboBox.ValueMember = "Key";
			}
			if (this.forumsListBox.DataSource != null)
			{
				this.forumsListBox.DisplayMember = "Value";
				this.forumsListBox.ValueMember = "Key";
			}
		}

		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private void questionsOnlyCheckBox_CheckedChanged(object sender, EventArgs e)
		{
			if (questionsOnlyCheckBox.Checked)
			{
				commentsOnlyCheckBox.Checked = false;
			}
			UpdateControls();
		}

		/// <summary>
		/// Updates the state of controls whose state depends on the state of other controls
		/// </summary>
		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private void UpdateControls()
		{
			// going from question only checked to not checked.
			if (!answerFiltersGroupBox.Enabled && questionsOnlyCheckBox.Checked)
			{
				// default to all questions
				allQuestionsRadioButton.Checked = true;
			}

			answerFiltersGroupBox.Enabled = questionsOnlyCheckBox.Checked;
			onlyAnsweredRadioButton.Enabled = questionsOnlyCheckBox.Checked;
			onlyUnansweredRadioButton.Enabled = questionsOnlyCheckBox.Checked;
			allQuestionsRadioButton.Enabled = questionsOnlyCheckBox.Checked;
			if (!allQuestionsRadioButton.Enabled)
			{
				allQuestionsRadioButton.Checked = false;
			}
			if (!onlyUnansweredRadioButton.Enabled)
			{
				onlyUnansweredRadioButton.Checked = false;
			}
			if (!onlyAnsweredRadioButton.Enabled)
			{
				onlyAnsweredRadioButton.Checked = false;
			}
		}

		/// <revisionHistory>
		/// <revision author="Peter Ritchie" date="13-jul=06">Created</revision>
		/// </revisionHistory>
		private void commentsOnlyCheckBox_CheckedChanged(object sender, EventArgs e)
		{
			if (commentsOnlyCheckBox.Checked)
			{
				questionsOnlyCheckBox.Checked = false;
			}
		}

		private bool processingSelections;
		private object processingSelectionsLock = new Object();

		private void forumsListBox_SelectedIndexChanged(object sender, EventArgs e)
		{
			lock (processingSelectionsLock)
			{
				if (!processingSelections)
				{
					processingSelections = true;
					try
					{
						if (forumsListBox.SelectedIndices.Count > 1)
						{
							// ensure "<All forums" is cleared if a forum is selected
							forumsListBox.SetSelected(0, false);
						}
						if (forumsListBox.SelectedIndices.Count == 0)
						{
							// ensure "<all forums" is selected if no forum is selected
							forumsListBox.SetSelected(0, true);
						}
					}
					finally
					{
						processingSelections = false;
					}
				}
			}
		}
    }
}

